<template>
  <div>
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    />
    <div v-if="true" class="doumee_table_header">
      <el-button
        v-if="true"
        v-preventReClick
        type="primary"
        @click="handleTransfer"
      >会员卡转账</el-button>
    </div>
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        label="转账订单号"
        prop="id"
        min-width="220"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="转账金额"
        prop="money"
        min-width="110"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="转出会员"
        prop="outMemberInfo"
        min-width="240"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="转入会员"
        prop="inMemberInfo"
        min-width="240"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="转账说明"
        prop="remarks"
        min-width="200"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="操作人"
        prop="creatorName"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="转账时间"
        prop="createTime"
        min-width="160"
        show-overflow-tooltip
      />
    </el-table>
    <!-- <div class="flex-cc doumee-pagination">
      <el-pagination
        background
        hide-on-single-page
        layout="prev, pager, next"
        :total="totalCount"
        :current-page.sync="page"
        @current-change="handleCurrentChange"
      />
    </div> -->
    <Paginations
      :total="totalCount"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
    <VipTransfer
      v-if="isShowVipTransfer"
      ref="VipTransferRef"
      @success="getList"
      @close="isShowVipTransfer = false"
    />
  </div>
</template>

<script>
import { transferList } from '@/api'
import { parseTime } from '@/utils'
import QueryForm from '@/components/QueryForm'
import VipTransfer from '../../vipTransfer/index.vue'
export default {
  name: 'VipTransferHistory',
  components: {
    QueryForm,
    VipTransfer
  },
  data() {
    return {
      isShowVipTransfer: false,
      queryFormConfig: {
        formItems: [{
          filed: 'transferNo',
          type: 'input',
          label: '转账订单号',
          placeholder: '请输入转账订单号',
          clearable: true
        }, {
          filed: 'outMemberInfo',
          type: 'input',
          label: '转出会员',
          placeholder: '会员昵称/手机号/卡号',
          clearable: true
        }, {
          filed: 'inMemberInfo',
          type: 'input',
          label: '转入会员',
          placeholder: '会员昵称/手机号/卡号',
          clearable: true
        }],
        online: true
      },
      totalCount: 0,
      pagination: {
        page: 1,
        rows: 10
      },
      list: [],
      listLoading: false,
      filters: {}
    }
  },
  created() {
    this.getList(1)
  },
  mounted() {
    this.$refs.table.doLayout()
  },
  methods: {
    handleTransfer() {
      this.isShowVipTransfer = true
      this.$nextTick(() => {
        this.$refs.VipTransferRef.isShow = true
      })
      // this.$router.push({ name: 'VipTransfer' })
    },
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      const venueId = sessionStorage.getItem('venueId')
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      pagination.firstQueryTime = parseTime(new Date())
      transferList({ pagination, param: { venueId, ...filters }})
        .then((res) => {
          this.listLoading = false
          if (res.errorCode !== '000000') return
          this.totalCount = res.totalCount
          this.list = res.recordList
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    clear() {
      this.filters = {}
      this.getList(1)
    }
  }
}
</script>
